<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@ page import="java.util.*"%>
<%@ page import="forum.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	String username = (String) request.getSession().getAttribute(
			"username");
	Boolean isModerator = (Boolean) request.getSession().getAttribute(
			"isModerator");
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Refresh" content="30">
<base href="<%=basePath%>">

<title>Posts list</title>
</head>
<body>

	<h2>Posts list</h2>
	<%
		List<Post> postsList = (ArrayList) request.getAttribute("posts");
		int threadID = ((Integer) request.getAttribute("threadID"))
				.intValue();

		for (Post p : postsList) {
	%>
	<hr>
	<br> #<%=p.getID()%>.
	<%
 	if (p.getParent() != null)
 			out.println("<u>Reply to post #" + p.getParent().getID()
 					+ "</u>");
 %>
	<br>
	<b><%=p.getAuthor()%></b> posted at
	<b><%=p.getDate()%></b>
	<br>
	<b>Subject: </b><%=p.getSubject()%>
	<br>
	<b>Content: </b><%=p.getContent()%>
	<br>
	<%
	if (p.getAuthor().equalsIgnoreCase(username))
		out.println("&nbsp &nbsp &nbsp <a href=\"viewPostsProcessor?do=edit&id="
					+ p.getID()
					+ "&author="
					+ p.getAuthor()
					+ "\">Edit</a>");
	if (p.getAuthor().equalsIgnoreCase(username)
			|| (isModerator != null && isModerator.booleanValue()))
			out.println("&nbsp &nbsp &nbsp <a href=\"viewPostsProcessor?do=delete&id="
					+ p.getID()
					+ "&author="
					+ p.getAuthor()
					+ "\">Delete</a>");
		}
	%>
	<br>
	<hr>
	<br>
	<%
		out.println("<a href=\"viewPostsProcessor?do=reply&id=" + threadID
				+ "\">Add post</a>");
	%>
	<br>
	<br>
	<a href="viewFriends">Show friends</a>
	<br>
	<a href="viewForums">Back to Forums</a>
	<br>
	<a href="logout">logout</a>

</body>
</html>